package com.may.nio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @program: com.may.netty
 * @description: 使用 FileChannel 读取文本
 * @author: Bobby.Ma
 * @create: 2020-08-02 15:15
 **/
public class NIOFileChannel02 {
    /**
     * logger
     */
    private static final Logger log = LoggerFactory.getLogger(NIOFileChannel02.class);

    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\19167\\Documents\\read.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        FileChannel fileChannel = fileInputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        fileChannel.read(byteBuffer);
        log.info(new String(byteBuffer.array()));
        fileInputStream.close();
    }
}
